import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.swing.JOptionPane;

import org.json.JSONArray;
import org.json.JSONObject;

import date.DateParser;
import Server.Client;
import SystemDataTypes.FlightData;
import SystemDataTypes.FlightPlan;
import SystemDataTypes.Vector3;

public class sendFlightPlan {

	/**
	 * @param args
	 */
	
	static String sendToHost;
	static int sendToPort;

	public static void main(String[] args) {
		
		// MANDAMOS A:
		 sendToHost = "localhost";
	
	//	 sendToHost = "10.2.100.41";
			sendToPort = 4019;
		
		String leavingDate = "05/08/2009@16:40";
		String arrivingDate = "05/08/2009@17:00";
		int flightId = 7;
		String aerolinea = "MACACO Airlines";
		String cancelled = "True"; // True o False
		String stops[] = {"JFK", "JFK-S", "CPH"};
		
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy@HH:mm");
        try {
        	
        	System.out.println("Parseado:" + sdf.parse(leavingDate));
        
            FlightPlan fp = new FlightPlan(flightId, aerolinea, sdf.parse(leavingDate), sdf.parse(arrivingDate),Boolean.parseBoolean(cancelled));
            fp.stops = stops;
            JSONObject jp = new JSONObject();
            jp.put("nOrden", DateParser.toString(new java.util.Date()));                
            jp.put("data",fp.toString());
              System.out.println(fp.toString());
                sendData(fp.toString());
            
           // System.out.println(jp.toString());

        } catch (Exception ex) {
           System.out.println(ex.getMessage());
        }        
	}
	
	private static void sendData(String data){              	           
	            boolean success;
                System.out.print("Trying to connect to " + sendToHost + ":" + sendToPort);                            	       
                success=true;
                Client c = new Client(sendToHost, sendToPort);
                try {
					c.sendNoResponseMessage(data);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					System.out.println("Unnable to connect");
				}
	}
}